/**
 *
 */
package com.angel.architecture.services;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.angel.architecture.BaseArchitectureTestCase;
import com.angel.architecture.exceptions.NonBusinessException;
import com.angel.architecture.persistence.beans.ConfigurationParameter;
import com.angel.architecture.persistence.beans.ParameterArea;
import com.angel.dao.generic.exceptions.OnPersitHibernateException;
import com.angel.mocks.architecture.services.AddressService;
import com.angel.mocks.factories.AddressFactory;
import com.angel.mocks.factories.ConfigurationParameterFactory;
import com.angel.mocks.factories.ParameterAreaFactory;
import com.angel.mocks.providers.Address;

/**
 * @author William
 *
 */
@Transactional(noRollbackForClassName = {"com.angel.architecture.services.ServiceTransactionTestCase"})
public class ServiceTransactionTestCase extends BaseArchitectureTestCase{

	@Autowired
	public ConfigurationParameterService configurationParameterService;

	@Autowired
	public ParameterAreaService parameterAreaService;

	@Autowired
	private AddressService addressService;

	@Test
	public void testValidCreateConfigurationParameterWithServiceMapped(){
		ParameterArea parameterArea = ParameterAreaFactory.createParameterArea();
		parameterAreaService.create(parameterArea);
		ConfigurationParameter configurationParameter = ConfigurationParameterFactory.createConfigurationParameter();
		configurationParameter.setParameterArea(parameterArea);
		configurationParameterService.create(configurationParameter);
	}

	@Test
	public void testInvalidCreateConfigurationParameterWithServiceMapped(){
		ConfigurationParameter configurationParameter = ConfigurationParameterFactory.createEmptyConfigurationParameter();
		try {
			configurationParameterService.create(configurationParameter);
			fail("It must throw a NonBusinessException because it creates an empty configuration parameter.");
		} catch (NonBusinessException e) {

		}
	}

	@Test
	public void testValidCreateAddressWithServiceNotMapped(){
		Address address = AddressFactory.createAddress();
		addressService.create(address);
	}

	@Test
	public void testInvalidCreateAddressWithServiceNotMapped(){
		Address address = AddressFactory.createEmptyAddress();
		try {
			addressService.create(address);
			fail("It must throw a NonBusinessException because it creates an empty address.");
		} catch (OnPersitHibernateException e) {

		}
	}
}
